package com.choosefine.paycenter.config;

import com.choosefine.common.url.UrlRegistrar;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * 项目启动完成后推送到权限和网关注册
 * @Author hujj
 * @Date 2017/6/8
 */
@Configuration
@Lazy
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    UrlRegistrar urlRegistrar;

    @Value("${dmsUrl}")
    final String dmsUrl = null;

    public void onApplicationEvent(ContextRefreshedEvent event)
    {
        // 在设定了dmsUrl的情况下，去推送
        if (!StringUtils.isEmpty(dmsUrl) && dmsUrl.startsWith("http")) {
            urlRegistrar.send();
        }
    }
}